﻿using System.Collections.Generic;
using System.Diagnostics;
using WebMonitor.Http;

namespace WebMonitor {
    public class PerfCounterController : Controller {
        public override string ViewName {
            get { return string.Format("{0}.Resources.Value.html", GetType().Assembly.FullName.Split(',')[0]); }
        }

        public override IDictionary<string, object> Execute(IHttpContext context) {
            var category = context.Request.QueryString["cat"];
            var counter = context.Request.QueryString["counter"];
            return new Dictionary<string, object> {
                {"value", GetPerfCounter(category, counter)}
            };
        }

        public float GetPerfCounter(string category, string counter) {
            using (var c = new PerformanceCounter(category, counter))
                return c.NextValue();
        }
    }
}